package com.jy.api.dao;

import com.jy.api.domain.KitchenPrintConfig;
import com.jy.api.domain.MakeOrderItem;
import com.jy.api.enums.OrderItemMakeType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface MakeOrderItemDao extends CrudRepository<MakeOrderItem, Integer> {

    List<MakeOrderItem> findAllByIdIn(List<Integer> itemIds);

    List<MakeOrderItem> findAllByStoreIdAndMakeTypeInOrderByAddTimeAsc(String storeId, List<OrderItemMakeType> makeTypes);

    Page<MakeOrderItem> findAllByStoreIdAndMakeTypeOrderByAddTimeAsc(String storeId, OrderItemMakeType deliveryIng, Pageable pageable);


    List<MakeOrderItem> findAllByStoreIdAndMakeTypeOrderByAddTimeAsc(String storeId, OrderItemMakeType deliveryIng);

    List<MakeOrderItem> findByOrderItemIdInOrderByIdAsc(List<String> orderItemId);
    @Modifying
    @Transactional
    @Query(value = "UPDATE `make_order_item`  SET  `make_type`  ='deliveryFinished'  WHERE   `store_id` =?   and `make_type` IN ('makeIng','deliveryIng')" ,nativeQuery = true)
    void updateAllOrderStatus(String storeId);
}
